#ifndef ROCKET_NET_TCP_TCP_SERVER_H
#define ROCKET_NET_TCP_TCP_SERVER_H

#include <set>

#include "../eventloop.h"
#include "../io_thread_group.h"
#include "net_addr.h"
#include "tcp_acceptor.h"
#include "tcp_connection.h"

namespace rocket {

class TcpServer {
  public:
    TcpServer(NetAddr::s_ptr local_addr);

    ~TcpServer();

    void start();

  private:
    void init();

    // 有新客户端连接时
    void onAccept();

  private:
    TcpAcceptor::s_ptr m_acceptor;

    NetAddr::s_ptr m_local_addr;

    // main Reactor
    EventLoop *m_main_event_loop{nullptr};

    // sub Reactor
    IOThreadGroup *m_io_thread_group{nullptr};

    FdEvent *m_listen_fd_event;

    int m_client_counts{0};

    std::set<TcpConnection::s_ptr> m_client;
};

} // namespace rocket

#endif
